package day9;
//2.借助于它wait()和notify()实现
public class Demo6 implements Runnable{
    int id;
    static int count;
    static int length;
    public Demo6(int id){
        this.id = id;
    }
    public void run() {
        String name = Thread.currentThread().getName();
        while (true){
            synchronized (Demo6.class) {
                if (count % length == id) {
                    System.out.println(name);
                    count++;
                    Demo6.class.notifyAll();
                }
                try {
                    Demo6.class.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }
    }

    public static void main(String[] args) {
        //new Thread(new Demo6(0),"A").start();
        //new Thread(new Demo6(1),"B").start();
        //new Thread(new Demo6(2),"C").start();
        Demo6.length = 10;
        for (int i = 0; i < Demo6.length; i++) {
            new Thread(new Demo6(i),(char)(65+i)+"").start();
        }
    }
}
